
(in-package :edec)

(defmacro gen-chk-sig (place)
  `(list* ',place (cdr (ssig-sign ,place))))

(defun verify-chk-sig (chk-sig)
  (with-simple-restart (continue "Check remaining signatures")
    (assert (apply #'ssig-verify
                   (eval (car chk-sig))
                   (cdr chk-sig))
        ()
      "Data does not match signature: ~A" (car chk-sig)
      )))

;; -------------------------------------------------
(with-ed-curve :curve1174
  (unless (boundp '*my-pkey*)
    (multiple-value-bind (pkey shares)
        (gen-key-pair)
      (distribute-shares shares)
      (setf *my-pkey* pkey)))
  (assert (ed-pt= *my-pkey*
                  (ed-mul *ed-gen* *my-skey*))
      ))
;; ---------------------------------------------------
#|
(with-ed-curve :curve1174
  (let ((*print-readably* t)
        (*print-radix*    t))
    (pprint
     (loop for sym in '(*my-pkey*
                        *my-skey*
                        *curve1174*
                        *curve-E382*
                        *curve41417*
                        *curve-Ed448*
                        *curve-e521*
                        *curve-Ed3363*
                        core-crypto::*wordlist*)
           collect
           (eval `(gen-chk-sig ,sym))
           ))))

#-:WINDOWS
(with-ed-curve :curve1174
  (let ((*print-readably* t)
        (*print-radix*    t))
    (pprint
     (loop for sym in '(pbc::*pairing-fr449-params*
                        pbc::*pairing-fr256-params*
                        pbc::*pairing-fr255-params*
                        pbc::*pairing-fr250-params*
                        pbc::*pairing-fr248-params*
                        pbc::*pairing-fr247-params*
                        pbc::*pairing-fr256-params-old*
                        pbc::*pairing-default-ar160-params*)
           collect
           (eval `(gen-chk-sig ,sym))
           ))))
|#
#||#
(with-ed-curve :curve1174
  (dolist (sig 
           '((*MY-PKEY*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  259108865966047524450453178644410951669150964589689171600580762429780230266.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "BF9C8556743DCD4A1855DAAD1C28B5BA5FBA5E77322799B3CEA6E2DF409AD7A8"))))
 (*MY-SKEY*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  789025864520186874636370842077330986813900303294056806055735244937475518272.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "6863479BEBA58E6CA5C096A37301C95C0ACFFC602EAD7F3653DAD825129CB1EA"))))
 (*CURVE1174*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  69595259109580330976521127159353595556216980814399669448513213486295644942.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "E6DC60409EFD17ECB1B0E478D3AE83099C34663D6A7A1D8134923851C3A9223D"))))
 (*CURVE-E382*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  416751640432371210061042114988754870350154102775406090180533829396900996648.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "2F01DA97D43EF6338A4009DC4EC579CAB384B90F72C6E4AFEAA13EA1C87A4C7F"))))
 (*CURVE41417*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  464228922210441192555369244366088472415762063274008396762609717135461343288.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "20A26A6EB9C21152FCEB8E88CF00A2CD3725FE8E226E6575A2EF2717F1314162"))))
 (*CURVE-ED448*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  477870705162571407740016113924009058134801568552535864319144259131406787215.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "F1BC0347C989EC78B781794C8C1A3842E8069134ABF3FFF46BC8581F585C5E00"))))
 (*CURVE-E521*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  360425645379329100784001170014015166258031181075373364315311434736951530585.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "78514B3B5B405DDB23B86BA3701A007BEB2E5D7242FE6C5199C93B34450578D6"))))
 (*CURVE-ED3363*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  121383999307238567111575417970436175436286447221680524192365856833055545236.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "2E27D7114BAF6B92546F54A65DD665F641454D57AE8E864DCD4A6DD61F0E3DB3"))))
 (CORE-CRYPTO::*WORDLIST*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  705466943643003149545350336880923072639899149405814702785381878607776046821.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "14D14EF321736AAD4600C50A9A77CF4D74127C638C3326B8F0C613DEC4190159"))))))
  (verify-chk-sig sig)))

#-:WINDOWS
(with-ed-curve :curve1174
  (dolist (sig
           '((PBC-INTERFACE::*PAIRING-FR449-PARAMS*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  567634031224075103458277995620484480966890591976384874346576208801461634490.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "2FFE5421824BBE2D2C34AD6EF42EA2A5A767A55D0C4A3B91E5CED02859F06D42"))))
 (PBC-INTERFACE::*PAIRING-FR256-PARAMS*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  13729535899391894587464717838898627614831747994732831369997072545871472882.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "010B8465473938715833C0E2D9AD76033AB947DDAA6B1F33DFB0741FC36E5751"))))
 (PBC-INTERFACE::*PAIRING-FR255-PARAMS*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  146913311914839357832818609433691276117903667559683461495173177972090195143.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "3202A55075FF0FDA92389F680CD9848FBFF86069C668B63170DD10F8C824C742"))))
 (PBC-INTERFACE::*PAIRING-FR250-PARAMS*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  182711763030100476720659762154254806352829833296584761328012844044705719121.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "0E73C2847510231EB6E4B097E6867F965BA29C7800A8F93AC59811254DAAB8B5"))))
 (PBC-INTERFACE::*PAIRING-FR248-PARAMS*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  347965866204566098551555447789353573381258081077886134615186426331342876096.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "1E6BB0FD9D429BA9DE56A1FF1CDFC11ED971269F582041FFF3A4CC0926CB6AED"))))
 (PBC-INTERFACE::*PAIRING-FR247-PARAMS*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  542155640578904169838495658575767213684293238389045491328987920127437984394.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "D1AF0C0A4D2252BFA443C0BD076B2FA15541C0023C80B71B3D6ACB23414F96D0"))))
 (PBC-INTERFACE::*PAIRING-FR256-PARAMS-OLD*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  297692343405769506554266456238063958808620663534763031574012188183659030830.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "7EEB55FE7BFF33DC4E63BBB2BE7F46967523A59D4E2B2CB567B4F6AC50D5DBCE"))))
 (PBC-INTERFACE::*PAIRING-DEFAULT-AR160-PARAMS*
  #S(ECC-CMPR-PT :CX 3238706287253458695043697889970663825594649144648473593115026994751520435692.)
  195961487675684930235628293478716013455218172168674655976564529825408459386.
  #.(make-instance 'HASH:HASH/256 :val (bev-vec (hex "4767C632BA1B964164F73F7927DAE55A3A51C09185988050C69683C37010D83F"))))))
    (verify-chk-sig sig)))


#||#
